package com.yxj.check;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.yxj.CheckSystemPicture.R;
import com.yxj.checksystempicture.i.OnItemClickListener;
import com.yxj.checksystempicture.m.CheckSystemPictureManager;
import com.yxj.checksystempicture.i.TakePhotoResultListener;
import com.yxj.checksystempicture.v.CheckPictureView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

        mCheckPictureView = findViewById(R.id.mCheckPictureView);
        mCheckPictureView.setCheckResultListener(new CheckPictureView.CheckResultListener() {
            @Override
            public void onCheckResult(List<CheckPictureView.CheckPictureBean> list) {
            }
        });
        mCheckPictureView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(CheckPictureView.CheckPictureBean item) {
                if (item.isDefaultImage) {
                    //选择图
                    CheckSystemPictureManager.getInstance().checkPicture();
                }else {
                    //显示全屏或者显示视频
                    Toast.makeText(MainActivity.this,"显示全屏或者显示视频",Toast.LENGTH_LONG).show();
                }
            }
        });
    }


    CheckPictureView mCheckPictureView ;
    private void init() {
        CheckSystemPictureManager.getInstance()
                .init(this, "com.yxj.CheckSysytemPicture.fileProvider",
                        new TakePhotoResultListener() {
                            @Override
                            public void onResult(String path) {
                                mCheckPictureView.addPath(path);
//                                showImage(path);
                            }
                        });
        findViewById(R.id.btnCheckPic).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CheckSystemPictureManager.getInstance().checkPicture();
            }
        });

        findViewById(R.id.btnTakePhoto).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CheckSystemPictureManager.getInstance().takePhoto();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        CheckSystemPictureManager.getInstance().onActivityResult(requestCode, resultCode, data);
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}